
import java.util.StringTokenizer;

class TimeInterval{
	
	protected String id;
	protected TimeInstant start;
	protected TimeInstant end;

	public TimeInterval(String id){
		this.id = id;	
		start = new TimeInstant();
		end = new TimeInstant();
	}
	
	public String getId(){return this.id;}
	public TimeInstant getStart(){return this.start;}
	public TimeInstant getEnd(){return this.end;}

	public void setStart(String time){
		//String time has the following format-> hour:minutes:seconds:day:month:year
		//symbol * is used as wildcard.	
		StringTokenizer st = new StringTokenizer(time, ":");
		
		String hour = st.nextToken();
		if(!hour.equals("*"))
			start.hour = Integer.parseInt(hour);
		String minutes = st.nextToken();
		if(!minutes.equals("*"))
			start.minutes = Integer.parseInt(minutes);
		String seconds = st.nextToken();
		if(!seconds.equals("*"))
			start.seconds = Integer.parseInt(seconds);
		String day = st.nextToken();
		if(!day.equals("*"))
			start.day = Integer.parseInt(day);
		String month = st.nextToken();
		if(!month.equals("*"))
			start.month = Integer.parseInt(month);
		String year = st.nextToken();
		if(!year.equals("*"))
			start.year = Integer.parseInt(year);

		
	}//end setStart
	
	public void setEnd(String time){
		//String time has the following format-> hour:minutes:seconds:day:month:year
		//symbol * is used as wildcard.
		//String time has the following format-> hour:minutes:seconds:day:month:year
		//symbol * is used as wildcard.	
		StringTokenizer st = new StringTokenizer(time, ":");
		
		String hour = st.nextToken();
		if(!hour.equals("*"))
			end.hour = Integer.parseInt(hour);
		String minutes = st.nextToken();
		if(!minutes.equals("*"))
			end.minutes = Integer.parseInt(minutes);
		String seconds = st.nextToken();
		if(!seconds.equals("*"))
			end.seconds = Integer.parseInt(seconds);
		String day = st.nextToken();
		if(!day.equals("*"))
			end.day = Integer.parseInt(day);
		String month = st.nextToken();
		if(!month.equals("*"))
			end.month = Integer.parseInt(month);
		String year = st.nextToken();
		if(!year.equals("*"))
			end.year = Integer.parseInt(year);
	}

	public String toString(){
		String text = "";
		text += (start.hour > -1 ?  start.hour+":" : "*:");
		text += (start.minutes > -1 ?  start.minutes+":" : "*:");
		text += (start.seconds > -1 ?  start.seconds+":" : "*:");
		text += (start.day > -1 ?  start.day+":" : "*:");
		text += (start.month > -1 ?  start.month+":" : "*:");
		text += (start.year > -1 ?  start.year+":" : "*");

		text += " - ";

		text += (end.hour > -1 ?  end.hour+":" : "*:");
		text += (end.minutes > -1 ?  end.minutes+":" : "*:");
		text += (end.seconds > -1 ?  end.seconds+":" : "*:");
		text += (end.day > -1 ?  end.day+":" : "*:");
		text += (end.month > -1 ?  end.month+":" : "*:");
		text += (end.year > -1 ?  end.year+":" : "*");
		return text;
	}
	
}//end class
